﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLayer;
using System.Configuration;
using System.Data;

using System.Data.SqlClient;

namespace Design
{
    public partial class WebForm10 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.IsInRole("administrator"))
            {
                Label lblUsersname = (Label)Master.FindControl("lblUsersname");
            }


        }

        protected void btnLog_Click(object sender, EventArgs e)
        {
            try
            {
                //SqlDataSource sds = new SqlDataSource();
                //sds.ConnectionString = ConfigurationManager.ConnectionStrings["con"].ToString();

                //sds.SelectParameters.Add("USERNAME", TypeCode.String, this.txtUsername.Text);
                //sds.SelectParameters.Add("USER_PASSWORD", TypeCode.String, this.txtPassword.Text);
                //sds.SelectParameters.Add("USER_EMAIL", TypeCode.String, this.txtUsername.Text);

                //sds.SelectCommand = "SELECT * FROM [SYS_USER] WHERE [USERNAME] = @USERNAME OR [USER_EMAIL] = @USER_EMAIL AND [USER_PASSWORD] = @USER_PASSWORD";

                //DataView dv = (DataView)sds.Select(DataSourceSelectArguments.Empty);

                //if (dv.Count == 0)
                //{
                //    this.lblinfo.ForeColor = System.Drawing.Color.Red;
                //    this.lblinfo.Text = "Invalid username and password!";
                //    return;
                //}
                //else
                //{
                //    //string user_type = sds.SelectCommand = "SELECT [USER_TYPE] FROM [SYS_USER] WHERE [USERNAME] = @USERNAME OR [USER_EMAIL] = @USER_EMAIL AND [USER_PASSWORD] = @USER_PASSWORD";

                //    Label lblUsersname = (Label)Master.FindControl("lblUsersname");

                //    if (lblUsersname != null)
                //    {
                //        lblUsersname.Text = "admin";
                //        lblUsersname.Visible = true;
                //    }

                //    this.Session["USERNAME"] = dv[0].Row["USERNAME"].ToString();
                //    Response.Redirect("~/Home.aspx");


                //    //END WORKING CODE

                //}
            }
            catch
            {

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            // Ensure that if Forms Authentication forces a mobile user 
            // to log in, we display the mobile login page
            string returnUrl = Request.QueryString["ReturnUrl"];
            if (!String.IsNullOrEmpty(returnUrl) && returnUrl.StartsWith("/Mobile/",StringComparison.OrdinalIgnoreCase))
            {
                Response.Redirect("~/Mobile/Account/Login.aspx?ReturnUrl="+ HttpUtility.UrlEncode(returnUrl));
            }

            HyperLink1.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(returnUrl);
        }



        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {

        }
    }
}